#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'xdao07'
import json
from time import sleep
import jenkins


# 设置Jenkins连接超时5秒
server = jenkins.Jenkins('http://192.168.10.112:18080', username='admin', password='admin', timeout=5)


jenkins_job = 'ZEP-BACKEND-JAVA'
arg_dic = {
    'git_url': 'http://192.168.10.112/ZEP-BACKEND/ZEP-BACKEND-JAVA.git',
    'branch_build': 'master',
    'package_name': 'javademo-0.0.1-SNAPSHOT.jar',
    'app_name': 'ZEP-BACKEND-JAVA',
    'deploy_version': '2020-0615-2135',
    'dir_build_file': 'javademo',
    'zip_package_name': 'javademo-1.0.tar.gz',
}

next_build_number = server.get_job_info(jenkins_job)['nextBuildNumber']
server.build_job(jenkins_job, arg_dic)
print(next_build_number)
sleep(10)
build_info = server.get_build_info(jenkins_job, next_build_number)
print(json.dumps(build_info, sort_keys=True, indent=4, separators=(',', ':')))


